<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class MyPromise{
				constructor(handle) {
				    this['status'] = "pedding";
					this['PromiseResult'] = undefined;
					
					handle(this._resolve.bind(this),this._reject.bind(this));
				}
				_resolve(arg){
					// console.log(this);
					this['status'] = "fufilled";
					this['PromiseResult'] = arg;
				}
				_reject(arg){
					this['status'] = "rejected";
					this['PromiseResult'] = arg;
				}
				then(onResolved,onRejected){
					console.log("then");
					onResolved && onResolved(this.PromiseResult);
					// then的链式操作 实现 1.返还this 2.返还实例化对象；
					return this;
				}
			}
			
			
			let p = new MyPromise((res,rej)=>{
				// 外部执行
				// res---->this._reslove  
				res("success");
				// rej("error");
				// rej--->this._reject
			});
			console.log(p);
			// p.then((res)=>{
			// 	console.log(res);
			// },(err)=>{
				
			// }).then().then().then();
    </script>
</body>
</html>